#-----------------------------------
# Name: Liam Macintyre
# Project Madlibs.py
# Period: 1
# Start Date: 9/18/2013
# Last Revision Date: 9/18/2013
# Version: 1.0.0
#----------------------------
import os

swearList = ["dumb",
             "stupid",
             "retard",
             "douche",
             "faggot",
             "dammit",
             "titty",
             "tit",
             "retarded",
             "fuck",
             "fuck u",
             "fuck you",
             "fart",
             "fag",
             "butt fucked",
             "fucked",
             "hell",
             "penis",
             "dick",
             "cock",
             "sack",
             "sucks",
             "sux",
             "gay",
             "ass",
             "a$$",
             "As$",
             "pig-nipple-titty",
             "jerking",
             "dickhole",
             "dick hole",
             "cum dumpster",
             "butt knocker",
             "fart knocker",
             "head",
             "biatch",
             "ratchet ass ho"]
            
             
bgColor = '2'
txtColor = '4'

def getMenuOption(maxOptions):
    option = ""
    goodOption = False
    while not goodOption:
        option = raw_input("Enter a number or S or Q> ")
        option = option.upper()
        if option == 'S':
            goodOption = True
        elif option == 'Q' :
            goodOption = True
        elif option == "":
            pass
        else:
            isNum = True
            for character in option:
                if character not in "0123456789":
                    isNum = False
            if isNum:
                if int(option) <= 0:
                    isNum = False
                elif int(option) > maxOptions:
                    isNum = False
            if isNum:
                goodOption = True
            else:
                print "Please type a number!"
        if not goodOption:
            print "Invalid Choice, please try again. "
    return option

def menu():
    print "Welcome to Madlibs"
    print "Please Select an Option B4 I Come Over There And Beat The Shit Out Of You!:"
    print " [1] The Brave Piece of Wood"
    print " [2] He's a ______!"
    print " [3] Ski Trip"
    print " [S] Settings"
    print " [Q] Quit"
    option = getMenuOption(3)
    return option

def getWord(prompt):
    word = ""
    goodWord = False
    while not goodWord:
        word = raw_input(prompt)
        if word.lower() not in swearList:
            isNum = False
            for digit in word:
                if digit in ".0123456789":
                    isNum = True
            if not isNum:
                goodWord = True
            else:
                print "Words don't have digits"
        else:
            print "Naughty user...please be polite!"
        if not goodWord:
            print "Please try again."
    return word

def getNumber(prompt, min = "", max = ""):
        num = ""
        goodNumber = False
        while not goodNumber:
            num = raw_input(prompt)
            isNum = True
            for digit in num:
                if digit not in ".0123456789":
                    isNum = False
            if isNum:
                if min != "":
                    if float(num) < min:
                        isNum = False
                if max != "":
                    if float(num) > max:
                        isNum = False
            if isNum:
                goodNumber = True
            else:
                print "Please enter a valid number"
        return num
                    
def getColor(prompt):
    colors = ["black",
              "blue",
              "green",
              "bright white",
              "light red",
              "red"]
    opt = ""
    goodColor = False
    while not goodColor:
        opt = raw_input(prompt)
        if opt.lower() in colors:
            goodColor = True
    if opt == "black":
        color = '0'
    elif opt == 'blue':
        color = '1'
    elif opt == 'green':
        color = '2'
    elif opt == 'bright white':
        color = 'F'
    elif opt == 'light red':
        color = 'C'
    elif opt == 'red':
        color = '4'
    return color
        
def getNHSkiMountain():
    NHSkiMountains = ["Abenaki Ski Area",
                    "Black Mountain",
                    "Bretton Woods",
                    "Cannon",
                    "Cranmore",
                    "Dartmouth Skiway",
                    "Eastman Recreation",
                    "Franconia Inn XC",
                    "Granite Gorge",
                    "Great Glen Trails",
                    "Gunstock",
                    "King Pine",
                    "Loon Mountain",
                    "McIntyre",
                    "Mount Sunapee",
                    "Nordic Skier Sports",
                    "Pats Peak",
                    "Ragged Mountain",
                    "Sunset Hill House",
                    "Waterville Valley",
                    "XC Resorts"]
    word = ""
    goodWord = False
    while not goodWord:
        word = raw_input("Enter an NHSkiMountain: ")
        word = word.capitalize()
        if word.lower() not in swearList:
            if word in NHSkiMountains:
                goodWord = True
            else:
                print "Only Enter NH Ski Mountains"
        else:
            print "Naughty user...please be polite!"
        if not goodWord:
            print "Please try again."
    return word
    
def story1():
    name1 = getWord("Enter a name: ")
    animal1 = getWord("Enter an animal: ")
    adjective1 = getWord("Enter an adjective: ")
    length1 = getNumber("Enter a number: ")
    food1 = getWord("Enter a food: ")
    place1 = getWord("Enter a place: ")
    drink1 = getWord ("Enter a drink: ")
    story = "There once was a piece of wood named " + name1 + ". "
    story += name1 + " was terrified of a "
    story += animal1 + ". "
    story += "That " + adjective1 + " was about " + length1 + " feet long. "
    story += "One day " + name1 + " went on a walk to the forest to get some"
    story += food1 + ". "
    story += name1 + " saw the " + animal1 + " and he got out a sword."
    story += " They battled for 10 minutes. " + "Finaly it was all over."
    story += " After that battle was over, " + "the wood went home to " + place1 + ". "
    story += "There, " + name1 + " went and got a " + drink1 + ". "
    story += "The End?!?"
    print story
 
def story2():
    noun1 = getWord("Enter a noun: ")
    adjective1 = getWord("Enter an adjective: ")
    verb1 = getWord("Enter a verb: ")
    name1 = getWord("Enter a name: ")
    animal1 = getWord("Enter an animal: ")
    animal2 = getWord("Enter an animal: ")
    story = "There once was a " + noun1 + " "
    story += "named " + name1 + ". "
    story += name1 + " was " + adjective1
    story += " and " + "is about to "
    story += verb1 + " a " + animal2 + "'s food . "
    story += "The " + animal2 + " came back while " + name1 + " was eating. "
    story += "The " + animal1 + " attacked " + name1 + " and the " + animal1 + " won. Obviously."
    print story

def story3():
    NHSkiMountain1 = getNHSkiMountain()
    name1 = getWord("Enter a name: ")
    place1 = getWord("Enter a place: ")
    name2 = getWord("Another name: ")
    verb1 = getWord("Enter a verb: ")
    color1 = getColor("Enter a color: ")
    adjective1 = getWord("Enter a adjective: ")
    story = "It was a early saturday morning in " + place1 + ". "
    story += name1 + " was sitting down in a cottage on a hill. "
    story += "'Let's go to " + NHSkiMountain1 + " today, It'll be fun.' "  
    story += "'Ok' said " + name2 + " let's go! "
    story += "Hold on " + name2 + " let me get some drinks for the road."
    story += " I heard " + NHSkiMountain1 + " is really warm today."
    story += " I hope the snow doesnt " + verb1 + " because that would suck."
    story += " As the kids go to the mountain, they dont realize that the snow is " + color1 + ". "
    story += "'That is " + verb1 + " why would that be there.' "
    story += "'oh man this is going to be " + adjective1 + ". "
    story += "THE END."
    print story
def settings():
    txtColor = getColor("Enter Text Color: ")
    bgColor = getColor("Enter Backgound Color: ")
    if txtColor != bgColor:
        os.system("color " + bgColor + txtColor)
    
def run():
    choice = ""
    while choice != 'Q':
        choice = menu()
        if choice == '1':
            story1()
        elif choice == '2':
            story2()
        elif choice == '3':
            story3()
        elif choice == 'S':
            settings()
        elif choice =='Q':  
            print " Goodbye "
            os.system("color " +bgColor + txtColor)
            raw_input("Press enter to exit")
        else:
            print "Something Awful Ocurred...can i have your number!"
    exit()
run()